<?php

/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */
class PacketNumService extends Service{

    public static function indexHeader(){
        $header = array(
            'id'            => array('text' => 'ID', 'width' => '80px'),
            'number'   => array('text' => '编号', 'width' => '160px'),
            'channel_name'       => array('text' => '渠道', 'width' => '200px'),
        	'create_time' => array('text' => '创建时间', 'width' => '200px'),
            'action'        => array('text' => '操作', 'width' => '60px'),
        );

        return $header;
    }

    public static function indexData($params){
        $modPacketNum = new ModPacketNum();
        $result = $modPacketNum->select($params);

        foreach($result as &$v){
        	$v['channel_name'] = $v['channel_name'];
            $v['create_time']     = date('Y-m-d H:i:s', $v['create_time']);
            $v['action']        = '<a href="'.PubFunc::buildUrl('/oss/?r=packetNum/edit').'&id='.$v['id'].'">编辑</a>';
            $v['action']        .= ' <a href="'.PubFunc::buildUrl('/oss/?r=packetNum/delete').'&id='.$v['id'].'" confirm="是否要删除该条信息?">删除</a>';
        }
        unset($v);

        return $result;
    }

    public static function doAdd($params){
        $user = AccAuth::me();

        $modPacketNum = new ModPacketNum();
        $modPacketNum->game          = $params['g'];
        $modPacketNum->number    = $params['number'];
        $modPacketNum->channel_id   = $params['channel_id'];
        $modPacketNum->create_user   = $user['UserID'];
        $modPacketNum->create_time   = time();
        $modPacketNum->update_user   = $user['UserID'];
        $modPacketNum->update_time   = time();

        return $modPacketNum->save();
    }

    public static function doEdit($id, $params){
        if(empty($id)) return false;

        $user = AccAuth::me();

        $modPacketNum = new ModPacketNum();
        $update = array();
        $update['game']         = $params['g'];
        $update['number']   = $params['number'];
        $update['channel_id']  = $params['channel_id'];
        $update['update_user']  = $user['UserID'];
        $update['update_time']  = time();

        $modPacketNum->updateByPk($id, $update);
        return true;
    }

    public static function get($id){
        $modPacketNum = new ModPacketNum();
        $obj = $modPacketNum->findByPk($id);

        if($obj){
            $info = $obj->getAttributes();

            return $info;
        }else{
            return false;
        }
    }

    public static function delete($id){
        if(empty($id)) return false;

        $modPacketNum = new ModPacketNum();
        $modPacketNum->deleteByPk($id);
        return true;
    }




}